jQuery.support.cors = true; // 解决IE ajax 进error
// 依赖jquery的请求
var http = {
  get: function(_url, _data, _fuc, _btn) {
    $.ajax({
      type: "GET",
      dataType: 'json',
      contentType: 'application/json',
      url: _url,
      data: _data,
      success: function (res) {
        http.changeBtn(_btn, false);
        _fuc(res);
      },
      beforeSend: function(xhr){
        http.changeBtn(_btn, true);
      },
      complete: function(xhr, msg){
        http.changeBtn(_btn, false);
      },
      error: function(e){
        http.changeBtn(_btn, false);
        msg.error('请求异常');
      }
    });
  },
  post: function(_url, _data, _fuc, _btn) {
    $.ajax({
      type: "POST",
      dataType: 'json',
      contentType: 'application/json',
      url: _url,
      data: _data ? JSON.stringify(_data) : '',
      success: function (res) {
        http.changeBtn(_btn, false);
        _fuc(res);
      },
      beforeSend: function(xhr){
        http.changeBtn(_btn, true);
      },
      complete: function(xhr, msg){
        http.changeBtn(_btn, false);
      },
      error: function(e){
        http.changeBtn(_btn, false);
        msg.error('请求异常');
      }
    });
  },
  /**
   * 改变按钮状态
   * @param {Object} _btn
   * @param {Object} _blen
   */
  changeBtn: function(_btn, _blen) {
    if (_btn) {
      _btn.attr('disabled', _blen);
    }
  }
};